package com.wang.controller;

import com.wang.service.UserService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @Author wang
 * @Date 2024/10/5 15:25
 * @PackageName:com.wang.controller
 * @ClassName: UserController
 * @Description: TODO
 * @Version 1.0
 */
@Controller
@RequestMapping("/user")
public class UserController {
    @Resource
    private UserService userService;

    @RequestMapping("/login")
    public String login(String username, String password, HttpServletRequest request) {
        if (userService.login(username, password)) {
            request.getSession().setAttribute("username", username);
            return "redirect:/main.jsp";
        } else {
            request.getSession().setAttribute("msg", "用户名或密码错误");
            return "redirect:/login.jsp";
        }
    }

}
